package com.teach.hotel;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * <pre>
 * 入住记录
 * ClassName : com.teach.Record
 * Author : J.L.Zhou
 * Date : 2019年6月2日 下午4:44:59
 * Version : V1.0
 * Copyright 2019 jlzhou.top Inc. All rights reserved. 
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目</pre>
 */
public class Record {
	
	public static List<Record> records = new ArrayList<>();
	private static Map<String,Record> inMap = new HashMap<>();
	
	private Date inDate;
	private Date outDate;
	/**
	 * 具体价格
	 */
	private Integer price;
	/**
	 * 押金
	 */
	private Integer cash;
	/**
	 * 租金
	 */
	private Integer rent;
	/**
	 * 其它消费
	 */
	private Integer expense;
	private Room room;
	private Type type;
	private User user;
	
	public Date getInDate() {
		return inDate;
	}
	public void setInDate(Date inDate) {
		this.inDate = inDate;
	}
	public Date getOutDate() {
		return outDate;
	}
	public void setOutDate(Date outDate) {
		this.outDate = outDate;
	}
	public Integer getPrice() {
		return price;
	}
	public void setPrice(Integer price) {
		this.price = price;
	}
	public Integer getCash() {
		return cash;
	}
	public void setCash(Integer cash) {
		this.cash = cash;
	}
	public Integer getRent() {
		return rent;
	}
	public void setRent(Integer rent) {
		this.rent = rent;
	}
	public Integer getExpense() {
		return expense;
	}
	public void setExpense(Integer expense) {
		this.expense = expense;
	}
	public Room getRoom() {
		return room;
	}
	public void setRoom(Room room) {
		this.room = room;
	}
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	/**
	 * 入住
	 */
	public static void inRoom() {
		Scanner in = new Scanner(System.in);
		Room r = Room.selectEmpty();
		User u = User.addOrSelect();
		System.out.println(u);
		Record rc = new Record();
		rc.setInDate(new Date());
		rc.setRoom(r);
		rc.setType(r.getType());
		rc.setUser(u);
		System.out.println("请选择具体房价:");
		System.out.println(" 0.标准房价");
		System.out.println(" 1.会员房价");
		System.out.println(" 2.活动房价");
		switch (in.nextInt()) {
		case 1:
			rc.setPrice(r.getType().getPrice2());
			break;
		case 2:
			rc.setPrice(r.getType().getPrice3());
			break;

		default:
			rc.setPrice(r.getType().getPrice1());
			break;
		}
		System.out.println("请输入押金:");
		rc.setCash(in.nextInt());
		rc.getRoom().setEnable(true);
		Record.records.add(rc);
		Record.inMap.put(r.getNum(), rc);
		System.out.println("入住成功");
		System.out.println(rc);
	}

	/**
	 * 退房
	 */
	public static void outRoom() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入退房房号：");
		String num = in.next();
		if(inMap.get(num)==null){
			System.out.println("该房号不正确");
		}else{
			Record rc = inMap.get(num);
			System.out.println("请输入入住天数：");
			int day = in.nextInt();
			rc.setRent(rc.getPrice()*day);
			System.out.println("请输入其它消费金额：");
			rc.setExpense(in.nextInt());
			rc.setOutDate(new Date());
			System.out.println("退房成功，找零："+(rc.getCash()-rc.getRent()-rc.getExpense()));
			rc.getRoom().setEnable(false);
			inMap.remove(num);
		}
	}
	@Override
	public String toString() {
		return "Record [inDate=" + inDate + ", outDate=" + outDate + ", price=" + price + ", cash=" + cash + ", rent="
				+ rent + ", expense=" + expense + ", room=" + room.getNum() + ", type=" + type.getName() + ", user=" + user.getName() + "]";
	}
	
	public static void lookAll(){
		for(Record r : records){
			System.out.println(r);
		}
	}
	
	
	
}
